package com.vr.cloudpicture.model.vo;

import cn.hutool.core.bean.BeanUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.vr.cloudpicture.model.entity.User;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 用户 VO
 *
 * @author hzh
 * @date 2025/04/28
 */
@Data
public class UserVO implements Serializable {
    private static final long serialVersionUID = 6792391705649307062L;

    /**
     * id
     */
    private Long id;

    /**
     * 账号
     */
    private String userAccount;

    /**
     * 用户昵称
     */
    private String userName;

    /**
     * 用户头像
     */
    private String userAvatar;

    /**
     * 用户简介
     */
    private String userProfile;

    /**
     * 用户角色：user/admin/vip
     */
    private String userRole;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createTime;

    /**
     * vo 到 obj
     *
     * @param userVO 用户 vo
     * @return {@code User }
     */
    public static User voToObj(UserVO userVO) {
        if (userVO == null) {
            return null;
        }
        return BeanUtil.toBean(userVO, User.class);
    }

    /**
     * obj 转 vo
     *
     * @param user 用户
     * @return {@code UserVO }
     */
    public static UserVO objToVO(User user) {
        if (user == null) {
            return null;
        }
        return BeanUtil.toBean(user, UserVO.class);
    }

}
